<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>成绩查询系统</title>
  <link rel="stylesheet" href="../static/styles.css">
  <style>
    /* 基本页面样式 */
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f7fa;
      margin: 0;
      padding: 0;
    }

    h1 {
      background-color: #007BFF;
      color: white;
      padding: 20px;
      text-align: center;
    }

    h2 {
      color: #007BFF;
    }

    /* 表单样式 */
    form {
      margin: 20px;
      padding: 20px;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    label {
      font-size: 16px;
      margin-right: 10px;
    }

    input[type="text"] {
      padding: 8px;
      font-size: 16px;
      width: 250px;
      margin-right: 10px;
      border: 1px solid #ddd;
      border-radius: 4px;
    }

    button[type="submit"] {
      padding: 10px 20px;
      font-size: 16px;
      background-color: #28a745;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    button[type="submit"]:hover {
      background-color: #218838;
    }

    /* 结果部分 */
    .result {
      margin-top: 20px;
      padding: 20px;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    .result h3 {
      color: #333;
    }

    .result p {
      font-size: 16px;
    }

    /* 表格样式 */
    table {
      width: 100%;
      margin-top: 20px;
      border-collapse: collapse;
      background-color: #fff;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }

    th, td {
      padding: 12px;
      text-align: left;
      border-bottom: 1px solid #ddd;
    }

    th {
      background-color: #007BFF;
      color: white;
    }

    tr:hover {
      background-color: #f1f1f1;
    }

    /* 空的结果展示 */
    .empty-message {
      text-align: center;
      font-size: 18px;
      color: #888;
    }
  </style>
</head>
<body>

<h1>成绩查询系统</h1>

<!-- 查询指定课程成绩 -->
<div>
  <h2>查询指定课程成绩</h2>
  <form action="/grades/{cname}" method="get">
    <label for="course-name">请输入课程名称：</label>
    <input type="text" id="course-name" name="cname" placeholder="请输入课程名称" required>
    <button type="submit">查询成绩</button>
  </form>

  <!-- 显示查询到的成绩 -->
  <div class="result">
    <h3>查询结果</h3>
    <div th:if="${cname != null}">
      <p>课程编号：<span th:text="${cname.cid}"></span></p>
      <p>课程名称：<span th:text="${cname.cname}"></span></p>
      <p>成绩：<span th:text="${cname.grades}"></span></p>
    </div>
    <div th:if="${cname == null}">
      <p>未找到该课程成绩。</p>
    </div>
  </div>
</div>

<!-- 显示所有成绩 -->
<!-- 查询所有成绩的按钮 -->
<div>
  <h2>查询所有成绩</h2>
  <form action="/grades" method="get">
    <button type="submit">查询所有成绩</button>
  </form>

  <!-- 显示所有成绩 -->
  <div class="result" th:if="${gradesList != null}">
    <h3>所有成绩</h3>
    <table>
      <thead>
      <tr>
        <th>课程名称</th>
        <th>学生姓名</th>
        <th>成绩</th>
      </tr>
      </thead>
      <tbody>
      <!-- 使用Thymeleaf循环输出所有成绩 -->
      <tr th:each="grade : ${gradesList}">
        <td th:text="${grade.cid}"></td>
        <td th:text="${grade.cname}"></td>
        <td th:text="${grade.grades}"></td>
      </tr>
      </tbody>
    </table>
  </div>
  <div th:if="${gradesList == null}" class="empty-message">
    <p>没有找到成绩数据。</p>
  </div>
</div>

</body>
</html>
